package com.tjc.section;


import java.util.List;
import java.util.stream.Collectors;


class SegmentPlan {
    public List<Section> findAll() {
        return List.of(new Section(0, 100), new Section(100, 200), new Section(200, 300), new Section(300, 400));
    }

    public List<Section> getOverlappingList(Section section) {
        return this.findAll().stream().map(o -> o.overlapping(section)).collect(Collectors.toList());
    }
}

class Section {
    int start;
    int end;

    public Section(int start, int end) {
        this.start = start;
        this.end = end;
    }

    public int getCount() {
        return Math.max(end - start, 0);
    }

    int getOverlappingAmount(Section other) {
        int newStart = Math.max(this.start, other.start);
        int newEnd = Math.min(this.end, other.end);
        return newEnd - newStart;
    }

    Section overlapping(Section other) {
        int newStart = Math.max(this.start, other.start);
        int newEnd = Math.min(this.end, other.end);
        return new Section(newStart, newEnd);
    }
}
